import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Exclude } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
import { Theme } from '../../theme/entities/theme.entity';
import { Task } from '../../../business/tasks/entities/task.entity';
import { File } from '../../file/entities/file.entity';
import { Log } from '../../log/entities/log.entity';
import { Role } from '../../role/entities/role.entity';
import { Menu } from '../../menu/entities/menu.entity';

@Entity('sys_user')
export class User {
  @ApiProperty({ type: String, description: 'id' })
  @PrimaryGeneratedColumn('uuid')
  id: string;
  @ApiProperty({ type: String, description: '用户名' })
  @Column({ type: 'varchar', length: 32, comment: '用户名' })
  username: string;
  // 隐藏
  @Exclude({ toPlainOnly: true }) // 输出屏蔽密码
  @Column({
    type: 'varchar',
    length: 200,
    nullable: false,
    comment: '用户登录密码',
  })
  password: string;
  @Exclude({ toPlainOnly: true }) // 输出屏蔽密码
  @Column({
    type: 'varchar',
    length: 200,
    comment: 'wxOpenId',
    default: null,
  })
  openId: string;

  // @Exclude({ toPlainOnly: true }) // 输出屏蔽盐
  // @Column({
  //   type: 'varchar',
  //   length: 200,
  //   comment: '盐',
  // })
  // salt: string;

  @Column({
    type: 'varchar',
    length: 32,
    comment: '用户登录账号',
    unique: true,
  })
  account: string;

  @Column({
    type: 'varchar',
    name: 'phone_num',
    length: 20,
    comment: '用户手机号码',
    default: null,
  })
  phoneNum: string;

  @Column({ type: 'varchar', comment: '邮箱地址', default: null })
  email: string;

  @Column({
    type: Number,
    default: 1,
    comment: '所属状态: 1-有效，0-禁用',
  })
  status: number;

  @Column({ type: 'varchar', comment: '头像地址', default: null })
  avatar: string;

  @Column({
    type: Number,
    default: 1,
    comment: '帐号类型：0-超管， 1-普通用户',
  })
  type: number;

  @Column({
    type: 'int',
    comment: '删除标记 0-未删除 1-删除',
    name: 'is_delete',
    default: 0,
  })
  isDelete: number;

  @CreateDateColumn({
    type: 'timestamp',
    name: 'create_date',
    comment: '创建时间',
  })
  createDate: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    name: 'update_date',
    comment: '更新时间',
  })
  updateDate: Date;

  @OneToMany((type) => Task, (task) => task.user, { eager: false })
  // @Exclude({ toPlainOnly: true })
  tasks: Task[];
  // // constructor(partial: Partial<User>) {
  // //   Object.assign(this, partial);
  // // }
  @ManyToOne((type) => Theme, (theme) => theme.user, { eager: false })
  theme: Theme;
  // @Column({
  //   type: 'string',
  //   name: 'theme_id',
  //   comment: '主题ID,默认主题',
  // })
  // themeId: string;
  @OneToMany((type) => File, (file) => file.user, { eager: false })
  file: File;
  @OneToMany((type) => Log, (log) => log.user, { eager: false })
  log: Log;
  @ManyToOne((type) => Role, (role) => role.user, { eager: false })
  roles: Role;
  @OneToMany((type) => Menu, (menu) => menu.user, { eager: false })
  menu: Menu;
}
